<template>
  <div class="login">
    <div class="login-box">
      <div class="head">
        <img src="../assets/logo.png" />
      </div>
      <h1>病床管理系统</h1>
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="用户名">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="form.password" show-password></el-input>
        </el-form-item>
      </el-form>
      <el-button type="primary" @click="login">登录</el-button>
    </div>
  </div>
</template>

<script>
export default {
  name: "Login",
  data() {
    return {
      form: {
        name: "",
        password: ""
      }
    };
  },
  created() {},
  methods: {
    login() {
      let params = {
        adminName: this.form.name,
        adminPassword: this.form.password
      };

      console.log(params);
      this.$axios.get("api/CjwAdmin/AdminLogin", { params }).then(res => {
        console.log(res.data);
        if (res.data) {
          if (res.data.state == 1) {
            this.$message({
              message: "登陆成功",
              type: "success"
            });
            this.$emit("adminApp", res.data);
            this.$router.push("/index");
          } else {
            this.$message("帐号无权限，请联系管理员");
          }
        } else {
          this.$message.error("帐号或者密码错误");
          // this.form.name = "";
          // this.form.password = "";
        }
      });
    }
    // test() {
    //   this.$axios.get("api/User/GetUser?id=1").then(res => {
    //     console.log(res);
    //   });
    // }
  }
};
</script>

<style scoped>
.login-box {
  position: absolute;
  top: 50%;
  left: 50%;
  height: 600px;
  width: 500px;
  /* background-color: #f5f5f5; */
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.login-box .el-form {
  width: 400px;
  padding-right: 70px;
}

.login-box .el-button {
  width: 300px;
}
</style>
